package h0726;

import java.util.LinkedList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
  * @description 提取字符串中的最长合法简单数学表达式
  * @author 不知名帅哥
  * @date 2024/7/26 8:54
  * @version 1.0
*/
public class TheLongestLegalSimpleMathematicalExpression {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(getRes(s));
    }

    private static long getRes(String s) {
        String maxLenExp = getMaxLenExp(s);
        if (maxLenExp.length()==0){
            return 0;
        }else {
            return calsExpStr(maxLenExp);
        }
    }

    private static long calsExpStr(String exp) {
        exp+="+0";

        //记录表达式中各块的操作数
        LinkedList<Long> stack=new LinkedList<>();
        StringBuilder numStr=new StringBuilder();
        long num_coef=1;

        for (int i = 0; i < exp.length(); i++) {
            char c=exp.charAt(i);
            if (c>='0'&&c<='9'){
                numStr.append(c);
                continue;
            }

            long num=num_coef*Long.parseLong(numStr.toString());
            stack.add(num);

            numStr=new StringBuilder();
            switch (c){
                case '+':num_coef=1;
                break;
                case '-':
                    num_coef=-1;
                    break;
                case '*':
                    num_coef=stack.removeLast();
                    break;
            }
        }
        long res=0;
        for (Long num : stack) {
            res+=num;
        }
        return res;
    }

    private static String getMaxLenExp(String s) {
        Matcher matcher = Pattern.compile("(\\d+[+*-])*\\d+").matcher(s);
        String maxLenExp="";
        while (matcher.find()){
            String exp = matcher.group(0);
            if (exp.length()>maxLenExp.length()){
                maxLenExp=exp;
            }
        }
        return maxLenExp;
    }
}
